---
title: "Sovereignty, Substance, and Public Support for European Courts’ Human Rights Rulings: Replication Archive"
author: "Mikael Rask Madsen, Juan Mayoral, Anton Strezhnev and Erik Voeten"
output:
  html_document:
    toc: true
    toc_float: true
    number_sections: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE)

```


```{r read data, echo=FALSE}
### Libraries
library(tidyverse)
library(haven)
library(ggplot2)
library(estimatr)
library(table1)
library(ggpubr)
library(knitr)

### Read in dataset
data <- read_csv("Data/final_data.csv")
```

```{r stratificationEst, echo=FALSE, message=FALSE, warning=FALSE}

# Stratified regression estimator
strat_reg <- function(formula, data, stratum){

  # Raw counts (use this do diagnostics if things go wrong)
  counts <- data %>% group_by(stratum) %>% summarize(N=n())
  
  # within each level of the data, fit the model in "formula"
  stratum_regs <- data %>% group_by(stratum) %>% group_map(~lm_robust(formula=formula, data=.))
  
  # get sizes of each stratum
  sample_sizes <- unlist(lapply(stratum_regs, function(x) x$nobs)) #nobs for most recent version of estimatr - if you're having issues, replace nobs with N (this changed at some point in that package's development)
  
  sample_shares <- sample_sizes/sum(sample_sizes)

  # get point estimates
  point_est <- sapply(stratum_regs, function(x) x$coefficients)
  
  if (!is.matrix(point_est)&is.vector(point_est)){
    point_est <- t(as.matrix(point_est))
  }
  # check for NAs
  if(sum(apply(point_est, 1, function(x) sum(is.na(x)))) > 0){
    print(counts[apply(point_est, 2, function(x) sum(is.na(x))) != 0,])
    stop("Error: NAs in stratified point estimates, coarsen strata to obtain enough units in each treatment condition per stratum")
  }

  var_est <- sapply(stratum_regs, function(x) abs(diag(vcov(x)))) # diagonals must be positive, some numerical issues w/ Variances of 0 (Pr(Y) = 1 or 0)

  if (!is.matrix(var_est)&is.vector(var_est)){
    var_est <- t(as.matrix(var_est))
  }
    # check for NAs
  if(sum(apply(var_est, 1, function(x) sum(is.na(x)))) > 0){
    print(counts[apply(var_est, 2, function(x) sum(is.na(x))) != 0,])
    stop("Error: NAs in stratified variance estimates, coarsen strata to obtain enough units in each treatment condition per stratum")
  }


  point_combined <- apply(point_est, 1, function(x) sum(x*sample_shares))
  se_combined <- apply(var_est, 1, function(x) sqrt(sum(x*sample_shares^2)))

  # Fix names for 1-length vectors
  if(length(point_combined) < 2){
    char_names <- c("(Mean)")
  }else{
    char_names <- names(point_combined)
  }
  
  # Save the results
  out_results <- data.frame(term = as.character(char_names), estimate=point_combined, std.error = se_combined)
  out_results$statistic <- out_results$estimate/out_results$std.error
  out_results$conf.low <- out_results$estimate - qnorm(.975)*out_results$std.error
  out_results$conf.high <- out_results$estimate + qnorm(.975)*out_results$std.error 

  return(out_results)
}

```

```{r strata, echo=FALSE, message=FALSE, warning=FALSE}

## Make the strata for covariate adjustment

# Four vars: Age, Gender, Education, Country

# Age - bin into categories
data <- data %>% mutate(ageBin = case_when(QQuotas2 >= 18 & QQuotas2 <= 34 ~ "18-34", 
                                           QQuotas2 >= 35 & QQuotas2 <= 50 ~ "35-50",
                                           QQuotas2 >= 51 ~"51+"))
# Gender - just take the response directly
data$gender <- data$QQuotas1

# Level of education - bin to college/non-college
data <- data %>% mutate(college = case_when(QQuotas3 == "ISCED 0:  Early childhood education (‘less than primary’ )" ~ "Non-College",
                                              QQuotas3 == "ISCED 1: Primary education" ~ "Non-College",
                                              QQuotas3 == "ISCED 2: Lower secondary education" ~ "Non-College",
                                              QQuotas3 == "ISCED 3: Upper secondary education" ~ "Non-College",
                                              QQuotas3 == "ISCED 4: Post-secondary non-tertiary education (NOT a University degree)" ~ "Non-College",
                                              QQuotas3 == "ISCED 5: Short-cycle tertiary education" ~ "College",
                                              QQuotas3 == "ISCED 6: Bachelor’s or equivalent level" ~ "College",
                                              QQuotas3 == "ISCED 7: Master’s or equivalent level" ~ "College",
                                              QQuotas3 == "ISCED 8: Doctoral or equivalent level" ~ "College"))


# Generate full-sample stratum bins
data$stratum <- paste(data$country, data$gender, data$college, data$ageBin, sep="|")

# Generate stratum without age because bins are too small
data$stratum_noage <- paste(data$country, data$gender, data$college, sep="|")

```


```{r data cleaning, echo=FALSE, message=FALSE, warning=FALSE}

##Create binary outcome variables
# Outcome 
data  <- data  %>% mutate(D1Agree = as.integer(!grepl("disagree", D1, ignore.case=T))) # Final decision
data  <- data  %>% mutate(D2Agree = as.integer(!grepl("disagree", D2, ignore.case=T))) # Should implement
data  <- data  %>% mutate(D3Agree = as.integer(!grepl("disagree", D3, ignore.case=T))) # Accept authority
data  <- data  %>% mutate(D4Agree = as.integer(!grepl("disagree", D4, ignore.case=T))) # Courts shouldn't intervene
data  <- data  %>% mutate(D5Agree = as.integer(!grepl("disagree", D5, ignore.case=T))) # Sue in domestic court
data  <- data  %>% mutate(D6Agree = as.integer(!grepl("disagree", D6, ignore.case=T))) # Stop letting IOs tell us what to do

# Fix missing data
data$D1Agree[is.na(data$D1)] <- NA
data$D2Agree[is.na(data$D2)] <- NA
data$D3Agree[is.na(data$D3)] <- NA
data$D4Agree[is.na(data$D4)] <- NA
data$D5Agree[is.na(data$D5)] <- NA
data$D6Agree[is.na(data$D6)] <- NA

# Vector with labels for each outcome - Used for graph labels
Outcomelabels= c("Agree with decision", "Should implement decision", "Accept authority of European courts","Courts shouldn't intervene", "Sue in domestic court","Stop letting IOs tell us")
Outcomelabelsshort= c("Agree", "Implement", "Accept authority","Intervene", "Sue domestic","Stop IOs")
Outcomelabelsprimary= c("Agree with decision", "Should implement decision", "Accept authority of European courts")

Outcomelabelsprimaryshort= c("Agree", "Implement", "Accept authority")
Outcomelabelssecondary= c("Courts shouldn't intervene", "Sue in domestic court","Stop letting IOs tell us")
Outcomelabelssecondaryshort= c("Intervene", "Sue domestic","Stop IOs")

# Continuous outcome variables for robustness checks
### Continuous agree variable
data <- data %>% mutate(D1AgreeC = case_when(D1 == "Strongly disagree" ~ 1,
                                                                    D1 == "Disagree" ~ 2,
                                                                    D1 == "Slightly disagree" ~ 3,
                                                                    D1 == "Slightly agree" ~ 4,
                                                                    D1 == "Agree" ~ 5,
                                                                    D1 == "Strongly agree" ~ 6))

data <- data %>% mutate(D2AgreeC = case_when(D2 == "Strongly disagree" ~ 1,
                                                                    D2 == "Disagree" ~ 2,
                                                                    D2 == "Slightly disagree" ~ 3,
                                                                    D2 == "Slightly agree" ~ 4,
                                                                    D2 == "Agree" ~ 5,
                                                                    D2 == "Strongly agree" ~ 6))

data <- data %>% mutate(D3AgreeC = case_when(D3 == "Strongly disagree" ~ 1,
                                                                    D3 == "Disagree" ~ 2,
                                                                    D3 == "Slightly disagree" ~ 3,
                                                                    D3 == "Slightly agree" ~ 4,
                                                                    D3 == "Agree" ~ 5,
                                                                    D3 == "Strongly agree" ~ 6))

data <- data %>% mutate(D4AgreeC = case_when(D4 == "Strongly disagree" ~ 1,
                                                                    D4 == "Disagree" ~ 2,
                                                                    D4 == "Slightly disagree" ~ 3,
                                                                    D4 == "Slightly agree" ~ 4,
                                                                    D4 == "Agree" ~ 5,
                                                                    D4 == "Strongly agree" ~ 6))

data <- data %>% mutate(D5AgreeC = case_when(D5 == "Strongly disagree" ~ 1,
                                                                    D5 == "Disagree" ~ 2,
                                                                    D5 == "Slightly disagree" ~ 3,
                                                                    D5 == "Slightly agree" ~ 4,
                                                                    D5 == "Agree" ~ 5,
                                                                    D5 == "Strongly agree" ~ 6))
data <- data %>% mutate(D6AgreeC = case_when(D6 == "Strongly disagree" ~ 1,
                                                                    D6 == "Disagree" ~ 2,
                                                                    D6 == "Slightly disagree" ~ 3,
                                                                    D6 == "Slightly agree" ~ 4,
                                                                    D6 == "Agree" ~ 5,
                                                                    D6 == "Strongly agree" ~ 6))


# Create moderator variables
data <- data %>% mutate(SatLaw = case_when(QA4 == "Dissatisfied" ~ 0, # Satisfied with the legal system in your country
                                                                    QA4 == "Very dissatisfied" ~ 0,
                                                                    QA4 == "Very Satisfied" ~ 1,
                                                                    QA4 == "Satisfied" ~ 1,
                                                                    QA4 == "Neither dissatisfied nor satisfied" ~ 0),
                        trust = case_when(QA1 == "You can't be too careful in dealing with people (1)" ~ 1, # Trust
                                        QA1 == "(2)" ~ 2,
                                        QA1 == "(3)" ~ 3,
                                        QA1 == "(4)" ~ 4,
                                        QA1 == "(5)" ~ 5,
                                        QA1 == "(6)" ~ 6,
                                        QA1 == "Most people can be trusted (7)" ~ 7),
                      ideology = case_when(QC1 == "Extreme Left (0)" ~ 0, # Political ideology (numerical)
                                        QC1 == "(1)" ~ 1,
                                        QC1 == "(2)" ~ 2,
                                        QC1 == "(3)" ~ 3,
                                        QC1 == "(4)" ~ 4,
                                        QC1 == "(5)" ~ 5,
                                        QC1 == "(6)" ~ 6,
                                        QC1 == "(7)" ~ 7,
                                        QC1 == "(8)" ~ 8,
                                        QC1 == "(9)" ~ 9,
                                        QC1 == "Extreme right (10)" ~ 10),
                             National = if_else(QC4 == "British only", 1,0), # National attachment (1 = consider themselves (NATION) only)
                             Refugee = if_else(QB9 == "To deny legal status to someone who did not misrepresent their situation (e.g. faces a death threat back home)", 0,1), # Refugee attitudes (sympathy w/ applicant)
                            EvictFair = if_else(QB10 == "To evict people who were treated unfairly by a landlord or mortgage company.", 0,1), # Sympathy to eviction applicant
                          EvictFair2 = case_when(QB5 == "Strongly agree" ~ 1, # Eviction/fairness (agreement scale)
                                              QB5 == "Agree" ~ 1,
                                              QB5 == "Slightly agree" ~ 1,
                                              QB5 ==  "Slightly disagree" ~ 0,
                                              QB5 == "Disagree" ~ 0,
                                              QB5 == "Strongly disagree" ~0),
                          LGBTNotSameRights = case_when(QB1 == "Strongly agree" ~ 0, # Sympathy towards LGBT group.
                                              QB1 == "Agree" ~ 0,
                                              QB1 == "Slightly agree" ~ 0,
                                              QB1 ==  "Slightly disagree" ~ 1,
                                              QB1 == "Disagree" ~ 1,
                                              QB1 == "Strongly disagree" ~ 1),
                           LGBTRights = case_when(QB1 == "Strongly agree" ~ 6, # LGBT rights
                                              QB1 == "Agree" ~ 5,
                                              QB1 == "Slightly agree" ~ 4,
                                              QB1 ==  "Slightly disagree" ~ 3,
                                              QB1 == "Disagree" ~ 2,
                                              QB1 == "Strongly disagree" ~ 1),
                      IslamSymbol = case_when(QB4 == "Strongly agree" ~ 0, # Sympathy towards applicant (islam/Quran burning)
                                              QB4 == "Agree" ~ 0,
                                              QB4 == "Slightly agree" ~ 0,
                                              QB4 ==  "Slightly disagree" ~ 1,
                                              QB4 == "Disagree" ~ 1,
                                              QB4 == "Strongly disagree" ~ 1),
                                            Immigrants = case_when(QB3 == "Strongly agree" ~ 1, # Attitudes towards immmigration
                                              QB3 == "Agree" ~ 1,
                                              QB3 == "Slightly agree" ~ 1,
                                              QB3 ==  "Slightly disagree" ~ 0,
                                              QB3 == "Disagree" ~ 0,
                                              QB3 == "Strongly disagree" ~ 0),
                             Aut1 = case_when(QC2_1 == "Strongly agree" ~ 0, # Authoritarianism scale - Q1
                                              QC2_1 == "Agree" ~ 1,
                                              QC2_1 == "Slightly agree" ~ 2,
                                              QC2_1 ==  "Slightly disagree" ~ 3,
                                              QC2_1 == "Disagree" ~ 4,
                                              QC2_1 == "Strongly disagree" ~5),
                              Aut2 = case_when(QC2_2 == "Strongly agree" ~ 5, # Authoritarianism scale - Q2
                                              QC2_2 == "Agree" ~ 4,
                                              QC2_2 == "Slightly agree" ~ 3,
                                              QC2_2 ==  "Slightly disagree" ~ 2,
                                              QC2_2 == "Disagree" ~ 2,
                                              QC2_2 == "Strongly disagree" ~2),
                              Aut3 = case_when(QC2_3 == "Strongly agree" ~ 5, # Authoritarianism scale - Q3
                                              QC2_3 == "Agree" ~ 4,
                                              QC2_3 == "Slightly agree" ~ 3,
                                              QC2_3 ==  "Slightly disagree" ~ 2,
                                              QC2_3 == "Disagree" ~ 1,
                                              QC2_3 == "Strongly disagree" ~0),
                              Aut4 = case_when(QC2_4 == "Strongly agree" ~ 0, # Authoritarianism scale - Q4
                                              QC2_4 == "Agree" ~ 1,
                                              QC2_4 == "Slightly agree" ~ 2,
                                              QC2_4 ==  "Slightly disagree" ~ 3,
                                              QC2_4 == "Disagree" ~ 4,
                                              QC2_4 == "Strongly disagree" ~5),
                             Autscale=(Aut1+Aut2+Aut3+Aut4)/20, # Combine the authoritarianism scale questions
                             Nat1 = case_when(QC2_5 == "Strongly agree" ~ 1, # Nationalism scale - Q1
                                              QC2_5 == "Agree" ~ .8,
                                              QC2_5 == "Slightly agree" ~ .6,
                                              QC2_5 ==  "Slightly disagree" ~ .4,
                                              QC2_5 == "Disagree" ~ .2,
                                              QC2_5 == "Strongly disagree" ~0),
                             Nat2 = case_when(QC2_6 == "Strongly agree" ~ 1,  # Nationalism scale - Q2
                                              QC2_6 == "Agree" ~ .8,
                                              QC2_6 == "Slightly agree" ~ .6,
                                              QC2_6 ==  "Slightly disagree" ~ .4,
                                              QC2_6 == "Disagree" ~ .2,
                                              QC2_6 == "Strongly disagree" ~0),
                              Nat3 = case_when(QC3 == "Very proud" ~ 1, # Nationalism scale - Q3
                                              QC3 == "Somewhat proud" ~ .75,
                                              QC3 == "Not very proud" ~ .6,
                                              QC3 ==  "Not proud at all" ~ .4),
                                         Natscale = National + Nat1 + Nat2 + Nat3
                                                   )

# Coarsen authoritarianism and nationalism scales
data <- data %>% mutate(aut=if_else(Autscale>.5, 1, 0))
data <- data %>% mutate(nat=if_else(Natscale>1.4, 1, 0))

```


```{r, vignette data, echo=FALSE, message=FALSE, warning=FALSE}

# Definition of vignette
data <- data %>% mutate(Vignette = case_when(vignette == "immigration" ~ "Deportation",
                                              vignette == "other"&(country=="uk"|country=="denmark")~ "Quran burning",
                                             vignette == "other"&(country=="spain"|country=="france") ~ "Eviction",
                                             vignette == "other"&(country=="poland") ~ "Pride Parade")
                                             )

# Categorize outcomes 
data <- data %>% mutate(caseOutcome = case_when(outcome == "can"&judgment=="agree" ~ 0,
                                                                        outcome == "can"&judgment=="disagree" ~ 1,
                                                                        outcome == "cannot"&judgment=="disagree" ~ 0,
                                                                      outcome == "cannot"&judgment=="agree" ~ 1,
                                                                      outcome == "can"&judgment=="nocourt" ~ 0,
                                                                      outcome == "cannot"&judgment=="nocourt" ~ 1),
                        caseOutcome=if_else(Vignette=="Pride Parade", caseOutcome*-1+1, caseOutcome)) ##Recodes the pride parade outcome

# Label vignettes by case outcomes
data <- data %>% mutate(VignetteOutcome = case_when(Vignette == "Quran burning" ~ "Quran burning, no fine",
                                             Vignette == "Eviction" ~ "Eviction canceled",
                                             Vignette == "Pride Parade" ~ "Pride parade not banned",
                                             Vignette == "Deportation" ~ "Deportation prohibited")
                                             )



### Six-category treatment
data <- data %>% mutate(treatmentBlock = case_when(outcome == "can"&judgment=="agree" ~ "Entitled, Upheld",
                                                                           outcome == "can"&judgment=="disagree" ~ "Entitled, Overturned",
                                                                           outcome == "cannot"&judgment=="disagree" ~ "Not Entitled, Overturned",
                                                                           outcome == "cannot"&judgment=="agree" ~ "Not Entitled, Upheld",
                                                                           outcome == "can"&judgment=="nocourt" ~ "Entitled, No Court",
                                                                           outcome == "cannot"&judgment=="nocourt" ~ "Not Entitled, No Court"))

### Treatment ordering with numeric labels
data <- data %>% mutate(treatmentLabel = case_when(treatmentBlock == "Entitled, Upheld" ~ "Applicant loses, EC defers (2)",
                                                   treatmentBlock == "Entitled, Overturned" ~ "Applicant wins, EC overturns (3)",
                                                   treatmentBlock == "Not Entitled, Overturned" ~ "Applicant loses, EC overturns (4)",
                                                   treatmentBlock == "Not Entitled, Upheld" ~ "Applicant wins, EC defers (1)",
                                                   treatmentBlock == "Entitled, No Court" ~ "Applicant loses, No EC (6)",
                                                   treatmentBlock == "Not Entitled, No Court" ~ "Applicant wins, No EC (5)"))


# Categorize individuals as unsympathetic towards applicant (1 is less sympathetic)
# This leverages the four sympathy covariates
data <- data %>% mutate(sympathy = case_when(Vignette == "Deportation" ~ Refugee,
                                               Vignette == "Quran burning" ~ IslamSymbol,
                                               Vignette == "Eviction" ~ EvictFair,
                                               Vignette == "Pride Parade" ~ LGBTNotSameRights))

                        
# Country labels with caps to look better in graphs
data$countryLabel <- data$country
data$countryLabel[data$country == "denmark"] <- "Denmark"
data$countryLabel[data$country == "uk"] <- "UK"
data$countryLabel[data$country == "poland"] <- "Poland"
data$countryLabel[data$country == "france"] <- "France"
data$countryLabel[data$country == "spain"] <- "Spain"


  
```


# Introduction

This file contains the annotated code used to generate all figures and tables in the paper "Sovereignty, Substance, and Public Support for European Courts’ Human Rights Rulings."

# Summary statistics

## Table 3 - General summary statistics for each variable

This table summarizes the mean and standard deviation for each of our three outcome variables of interest along with four of the moderators that we examine for each country and vignette.


```{r, table 3 summary, results='asis'}

# Assign labels to each of the variables
table1::label(data$D1Agree)       <- "Agreement"
table1::label(data$D2Agree)       <- "Implementation"
table1::label(data$D3Agree)       <- "Authority"
table1::label(data$SatLaw)       <- "Satisfaction Domestic Law"
table1::label(data$sympathy)       <- "Sympathy Applicant"
table1::label(data$National)       <- "Nationalist"
table1::label(data$Autscale)       <- "Authoritarianism"

# Part 1
table1(~ D1Agree + D2Agree + D3Agree + SatLaw + sympathy + National + Autscale| countryLabel*Vignette, data=filter(data, Vignette=="Deportation"), render="Mean (SD)")

# Part 2
table1(~ D1Agree + D2Agree + D3Agree + SatLaw + sympathy + National + Autscale| countryLabel*Vignette, data=filter(data, Vignette=="Quran burning"|Vignette == "Eviction"), render="Mean (SD)")

```

## Validating the authoritarianism scale

The authoritarianism measure is only moderately correlated with the nationalism measure.

```{r correlation between nationalism and authoritarianism scales}

cor(data$Autscale, data$Natscale, method = "pearson", use = "complete.obs")

```
However, both do appear to have power in predicting whether respondents intend to vote for far-right parties. First, for Denmark:

```{r nationalism and authoritarianism by party - denmark, echo=FALSE}

# Subset to danish
data_denmark <- data %>% filter(country == "denmark")

# Label the table
table1::label(data_denmark$`QE5-DA`) <- "Intend to vote for..."
table1::label(data_denmark$aut) <- "Authoritarian"
table1::label(data_denmark$National) <- "Nationalist"

# Authoritarianism by voting intent
table1(~ aut + National | `QE5-DA`  , data=data_denmark, render="Mean")

```

Next, for France

```{r nationalism and authoritarianism by party - france, echo=FALSE}

# Subset to french
data_france <- data %>% filter(country == "france")

# Label the table
table1::label(data_france$`QE5-FR`) <- "Intend to vote for..."
table1::label(data_france$aut) <- "Authoritarian"
table1::label(data_france$National) <- "Nationalist"

# Authoritarianism by voting intent
table1(~ aut + National | `QE5-FR`  , data=data_france, render="Mean")

```

Next, for Spain

```{r nationalism and authoritarianism by party - spain, echo=FALSE}

# Subset to french
data_spain <- data %>% filter(country == "spain")

# Label the table
table1::label(data_spain$`QE5-ES`) <- "Intend to vote for..."
table1::label(data_spain$aut) <- "Authoritarian"
table1::label(data_spain$National) <- "Nationalist"

# Authoritarianism by voting intent
table1(~ aut + National | `QE5-ES`  , data=data_spain, render="Mean")

```

For Poland

```{r nationalism and authoritarianism by party - poland, echo=FALSE}

# Subset to french
data_poland <- data %>% filter(country == "poland")

# Label the table
table1::label(data_poland$`QE5-PL`) <- "Intend to vote for..."
table1::label(data_poland$aut) <- "Authoritarian"
table1::label(data_poland$National) <- "Nationalist"

# Authoritarianism by voting intent
table1(~ aut + National | `QE5-PL`  , data=data_poland, render="Mean")

```

And for the UK.

```{r nationalism and authoritarianism by party - uk, echo=FALSE}

# Subset to french
data_uk <- data %>% filter(country == "uk")

# Label the table
table1::label(data_uk$`QE5-UK`) <- "Intend to vote for..."
table1::label(data_uk$aut) <- "Authoritarian"
table1::label(data_uk$National) <- "Nationalist"

# Authoritarianism by voting intent
table1(~ aut + National | `QE5-UK`  , data=data_uk, render="Mean")

```

Overall, euroscepticism in the sample was slightly higher than recent Eurobarometer benchmarks

```{r euroscepticism}

# Share in each country that think EU membership is bad/very bad
knitr::kable(data %>% group_by(country) %>% summarize(eu_bad = mean(QA2 == "Bad"|QA2 == "Very bad", na.rm=T)), digits = 3)

```
# Main Results

## Summary of treatment effects

Figure 1 -- summary of proportion agreeing with each outcome by treatment and vignette.

```{r figure 1, echo=F}

# Generate summary data frame
dfsum <- data %>% dplyr::select(D1Agree:D3Agree, treatmentLabel, Vignette, country, stratum) %>% filter(!(Vignette == "Pride Parade")) %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outcome", values_to = "agree") %>%
         group_by( outcome, treatmentLabel, Vignette) %>% do(strat_reg(agree ~ 1, data=.))

# Plot it
p <- ggplot(dfsum, aes(x=outcome, y=estimate, colour=treatmentLabel)) + 
    geom_pointrange(aes(ymin=conf.low, ymax=conf.high),
                  size=.3,    width=.2,
                  position=position_dodge(.9)) + 
  geom_vline(xintercept=1.5, lty=2) + geom_vline(xintercept=2.5, lty=2) + scale_y_continuous(limits=c(0.3, 1)) + labs(colour = "Treatment") +
 theme_light() + scale_x_discrete(       labels=Outcomelabelsprimaryshort) + ylab("Proportion Agree") +xlab("Outcome")+ facet_wrap(~Vignette, ncol=1) + scale_color_manual(values=c("#FF0000", "#FF8000", "#0000FF", "#0080FF", "#000000", "#808080"))

# Print it
print(p)

# Save it
ggsave("Figures//Figure 1 - Treatment Summaries.png", plot=p, height=5, width=6.5, units="in")


```

## H1: Deference

Figure 2: Average treatment effects of European court disagreeing with domestic court

```{r figure 2, echo = F}

# Generate a summary data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(tidy(lm_lin(agree ~ judgment , covariates = ~ stratum, data=.))) %>% #lin estimator is equivalent to stratification w/ discrete covariate
            ungroup() 

# Order the levels of the outcome
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

#Plot it
 p <- ggplot(filter(dfcoef,term=="judgmentdisagree"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~Vignette, ncol=1)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabelsprimary)) + ggtitle("Effect of EC disagreeing with domestic court")

# Print it
print(p)

# Save it
ggsave("Figures//Figure 2 - H1.png", plot=p, height=4, width=6, units="in")
```

Is there any variation across countries? 

```{r, echo = F, fig.height=10, fig.width=8}

# Generate the summary data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, country=countryLabel, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette, country) %>%
           do(tidy(lm_lin(agree ~ judgment , covariates = ~stratum, data=.))) %>%
            ungroup() 

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef,term=="judgmentdisagree"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~Vignette + country, ncol=3)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabelsprimary)) + ggtitle("Effect of EC disagreeing with domestic court by country")

 # Print it
print(p)

```

What happens if we average over the two vignettes in each country?

```{r, echo = F, messages = F, fig.height=5, fig.width=10}

# Generate the summary data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, country=countryLabel, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, country) %>%
           do(tidy(lm_lin(agree ~ judgment , covariates = ~stratum, data=.))) %>%
            ungroup() 

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef,term=="judgmentdisagree"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~ country, ncol=5)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabelsprimary)) + ggtitle("Effect of EC disagreeing with domestic court by country (averaging over vignettes)")

 # Print it
print(p)

```

Figure 3: Heterogeneity by satisfaction with domestic rule of law.

```{r figure 3, echo = F, fig.height=6, fig.width=6}

# Generate the effect data frame for both sub-groups (satisfied and not satisfied)
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, SatLaw, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(strat_reg(agree ~ judgment*SatLaw , data=., stratum=stratum)) %>% mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="judgmentdisagree",
                            "Not satisfied", term))

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, SatLaw, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  mutate(SatLaw2 = SatLaw*-1+1) %>%
           do(strat_reg(agree ~ judgment*SatLaw2 , data=., stratum=stratum)) %>% mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="judgmentdisagree",
                            "Satisfied", term))
                 
dfcoef <- bind_rows(dfcoef,dfcoefflip)

## Reverse order of plotting
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "Not satisfied" | term == "Satisfied"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, colour = term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = 1)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour = "Rule of law\nsatisfaction") + 
  facet_wrap(~Vignette, ncol=1)    + theme_bw()  + ggtitle("Effect of EC disagreement,\nby satisfaction with domestic rule of law") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimary) + geom_vline(xintercept=1.5, lty=3) + geom_vline(xintercept=2.5, lty=3) + ylab("Estimate") +
   scale_color_manual(values=c("#000000", "#808080"))

# Print it
print(p)

# Save it
ggsave("Figures/Figure 3 - H1 by domestic rule of law.png", plot=p, height=6, width=6, units="in")

```

Is there an interaction effect if we subset to UK/Denmark in particular? Not statistically significant.

```{r, echo = F, fig.height=7, fig.width=6}

# Generate the effect data frame for both sub-groups (satisfied and not satisfied)
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, country, caseOutcome, judgment, VignetteOutcome, Vignette, SatLaw, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% filter(country == "uk"|country == "denmark") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(strat_reg(agree ~ judgment*SatLaw , data=., stratum=stratum)) %>% mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="judgmentdisagree",
                            "Not satisfied", term))

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, country, caseOutcome, judgment, VignetteOutcome, Vignette, SatLaw, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt")  %>% filter(country == "uk"|country == "denmark") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  mutate(SatLaw2 = SatLaw*-1+1) %>%
           do(strat_reg(agree ~ judgment*SatLaw2 , data=., stratum=stratum)) %>% mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="judgmentdisagree",
                            "Satisfied", term))
                 
dfcoef <- bind_rows(dfcoef,dfcoefflip)

## Reverse order of plotting
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "Not satisfied" | term == "Satisfied"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, colour = term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = 1)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour = "Rule of law\nsatisfaction") + 
  facet_wrap(~Vignette, ncol=1)    + theme_bw()  + ggtitle("Effect of EC disagreement,\nby satisfaction with domestic rule of law\n(UK/Denmark Only)") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimary) + geom_vline(xintercept=1.5, lty=3) + geom_vline(xintercept=2.5, lty=3) + ylab("Estimate") +
   scale_color_manual(values=c("#000000", "#808080"))

# Print it
print(p)

```

```{r, echo = F, fig.width=7, height=4}

# Generate the interaction effect data frame 
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, country, caseOutcome, judgment, VignetteOutcome, Vignette, SatLaw, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% filter(country == "uk"|country == "denmark") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(strat_reg(agree ~ judgment*SatLaw , data=., stratum=stratum)) 


dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "judgmentdisagree:SatLaw"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = 1)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour = "Rule of law\nsatistfaction") + 
  facet_wrap(~Vignette, ncol=1)    + theme_bw()  + ggtitle("Difference in effect of EC disagreement between\nrespondentssatisfied with domestic rule of law\nand respondents dissatisfied (UK/Denmark Only)") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimary) + ylab("Estimate") 

# Print it
print(p)

```

## H2: Outcome

Figure 4 - Effects of case outcomes

```{r figure 4, echo = F}

# Generate the effect data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, stratum) %>% filter(VignetteOutcome != "Pride parade not banned") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(tidy(lm_lin(agree ~ caseOutcome , covariates = ~stratum, data=.)))  %>%
            ungroup() 

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "caseOutcome"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~VignetteOutcome, ncol=1)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabels[1:3])) + ggtitle("Effect of case outcome")

# Print it
print(p)

# Save it
ggsave("Figures/Figure 4 - H2.png", plot=p, height=4, width=6, units="in")
```

Are the case outcome effects larger than the deference effects? Here we test explicitly for whether there exists a difference between the outcome effect and the sovereignty effect. In a fully randomized 2x2 experiment, this amounts to estimating the difference between the percent that agree when the outcome condition is unfavorable and there is no sovereignty effect (the European court upholds) and the percent that agree when the outcome condition is favorable and there is a sovereignty effect (the European court overturns). 

```{r}

#Grouping data and estimating models 
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, VignetteOutcome, stratum) %>% filter(Vignette != "Pride Parade") %>%
  filter(judgment != "nocourt") %>% filter((judgment == "agree"&caseOutcome==1)|(judgment=="disagree"&caseOutcome==0)) %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(tidy(lm_lin(agree ~ caseOutcome , covariates = ~stratum, data=.)))  %>%
            ungroup() 

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "caseOutcome"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~Vignette, ncol=1)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabels[1:3])) + ggtitle("Difference between case outcome effect\nand sovereignty effect")

# Print it
print(p)

```

Figure 5 - Interactions by sympathy to the applicants.

```{r figure 5, fig.width=6, fig.height=6}

#Grouping data and estimating models for both levels of sympathy
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, sympathy, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*sympathy , data=., stratum=stratum)) %>%   mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="caseOutcome",
                            "More sympathetic", term))
                   

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette,  sympathy, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
  mutate(sympathy2 = sympathy*-1+1) %>%
           do(strat_reg(agree ~ caseOutcome*sympathy2 , data=., stratum=stratum)) %>%   mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="caseOutcome",
                            "Unsympathetic", term))
                 
dfcoef <- bind_rows(dfcoef,dfcoefflip)

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "More sympathetic" | term == "Unsympathetic"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, colour = term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = 1)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour="Sympathy towards\nrights claimant") +
  facet_wrap(~VignetteOutcome, ncol=1)    + theme_bw()  + ggtitle("Effect of Outcome,\nby predispositions towards rights claimant") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimary) +   geom_vline(xintercept=1.5, lty=3) + geom_vline(xintercept=2.5, lty=3) + ylab("Estimate") +
   scale_color_manual(values=c("#808080", "#000000"))

# Print it
print(p)

# Save it
ggsave("Figures/Figure 5 - H2 - Interactions with sympathy.png", plot=p, height=6, width=6, units="in")
```

```{r, echo = F, messages = F, fig.width=8, fig.height = 6}

# Grouping data and estimating models 
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, sympathy, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*sympathy , data=., stratum=stratum))

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "caseOutcome:sympathy"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") +
  facet_wrap(~VignetteOutcome, ncol=1)    + theme_bw()  + ggtitle("Difference in effect of outcome\nbetween unsympathetic and more sympathetic respondents") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimary) +  ylab("Estimate")

# Print it
print(p)

```

## Effect heterogeneity by nationalism

What is the share of respondents who generally believe their country should accept the authority of European courts by nationalism, irrespective of treatment condition?

```{r}

knitr::kable(data %>% filter(!is.na(National)) %>% group_by(country, National) %>% summarize(shareAccept = mean(D3Agree, na.rm=T)), digits = 3)

```

Figure 6 - Heterogeneity in both treatments by nationalism

```{r figure 6, echo = F, fig.width=8, fig.height=8}

### EC disagrees

#Group data and estimate interactions for nationalism for EC disagree/agree
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, VignetteOutcome, National, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  do(strat_reg(agree ~ judgment*National , data=., stratum=stratum))  %>%  mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="judgmentdisagree",
                            "Not Nationalist", term))
                   
dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, VignetteOutcome, National, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  mutate(National2 = National*-1+1) %>%
  do(strat_reg(agree ~ judgment*National2 , data=., stratum=stratum))  %>%  mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="judgmentdisagree",
                            "Nationalist", term))
                 
dfcoef <- bind_rows(dfcoef,dfcoefflip)

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Make component plot (left-side)
 p <- ggplot(filter(dfcoef, term == "Not Nationalist" | term == "Nationalist"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, colour = term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = 1)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour="Nationalism") +
  facet_wrap(~Vignette, ncol=1)    + theme_bw()  +  scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimaryshort) +   geom_vline(xintercept=1.5, lty=3) + geom_vline(xintercept=2.5, lty=3) + ylab("Estimate") + ggtitle ("EC disagrees") +
   scale_color_manual(values=c("#000000", "#808080"))

### Applicant win
 
#Group data and estimate interactions for nationalism for applicant outcome
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, National, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*National , stratum=stratum, data=.)) %>% mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="caseOutcome",
                            "Not Nationalist", term))
                   

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, National, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
  mutate(National2 = National*-1+1) %>%
           do(strat_reg(agree ~ caseOutcome*National2, stratum=stratum, data=.)) %>% mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="caseOutcome",
                            "Nationalist", term))
                 
dfcoef <- bind_rows(dfcoef,dfcoefflip)

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Make component plot (right-side)
 r <- ggplot(filter(dfcoef, term == "Not Nationalist" | term == "Nationalist"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, colour = term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour="Nationalism") +
  facet_wrap(~VignetteOutcome, ncol=1)    + theme_bw()  +   geom_vline(xintercept=1.5, lty=3) + geom_vline(xintercept=2.5, lty=3) + ylab("Estimate") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimaryshort) + ggtitle ("Applicant win")+
   scale_color_manual(values=c("#000000", "#808080"))

 
### Merge the two plots
figure <- ggarrange(p, r,
                    ncol = 2, nrow = 1, common.legend = TRUE, legend = "bottom")

# Print it
print(figure)

# Save it
ggsave("Figures/Figure 6 - heterogeneity by nationalism.png", plot=figure, height=8, width=8, units="in")


```

## Effect heterogeneity by authoritarianism

Figure 7 - differences in treatment effects by respondent authoritarianism

```{r figure 7, fig.width=8, fig.height=8}

### EC disagrees

#Group data and estimate interactions for authoritarianism for EC disagree/agree

dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, VignetteOutcome, aut, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  do(strat_reg(agree ~ judgment*aut , data=., stratum=stratum))  %>%  mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="judgmentdisagree",
                            "Not authoritarian", term))
                   

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, VignetteOutcome, aut, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  mutate(aut2 = aut*-1+1) %>%
  do(strat_reg(agree ~ judgment*aut2 , data=., stratum=stratum))  %>%  mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="judgmentdisagree",
                            "Authoritarian", term))
                 
dfcoef <- bind_rows(dfcoef,dfcoefflip)

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

 p <- ggplot(filter(dfcoef, term == "Not authoritarian" | term == "Authoritarian"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, colour = term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = 1)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour="Authoritarianism") +
  facet_wrap(~Vignette, ncol=1)    + theme_bw()  +  scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimaryshort) +   geom_vline(xintercept=1.5, lty=3) + geom_vline(xintercept=2.5, lty=3) + ylab("Estimate") + ggtitle ("EC disagrees") +
   scale_color_manual(values=c("#000000", "#808080"))

### Applicant win
 
# Group data and estimate interactions for authoritarianism for applicant outcome
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, aut, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*aut , stratum=stratum, data=.)) %>% mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="caseOutcome",
                            "Not authoritarian", term))
                   

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, aut, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
  mutate(aut2 = aut*-1+1) %>%
           do(strat_reg(agree ~ caseOutcome*aut2, stratum=stratum, data=.)) %>% mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="caseOutcome",
                            "Authoritarian", term))
                 
dfcoef <- bind_rows(dfcoef,dfcoefflip)

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

 r <- ggplot(filter(dfcoef, term == "Not authoritarian" | term == "Authoritarian"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, colour = term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour="Authoritarianism") +
  facet_wrap(~VignetteOutcome, ncol=1)    + theme_bw()  +   geom_vline(xintercept=1.5, lty=3) + geom_vline(xintercept=2.5, lty=3) + ylab("Estimate") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimaryshort) + ggtitle ("Applicant win")+
   scale_color_manual(values=c("#000000", "#808080"))

# Merge the two plots
figure <- ggarrange(p, r,
                    ncol = 2, nrow = 1, common.legend = TRUE, legend = "bottom")

# Print it
print(figure)

# Save it
ggsave("Figures/Figure 7 - heterogeneity by authoritarianism.png", plot=figure, height=8, width=8, units="in")
```

# Appendix Analyses


## Appendix C: Pride parade vignette

Figure C1 - Results of the Pride parade vignette, EC disagreement treatment  (omitted from main text due to implementation problems)

```{r figure c1, echo = F, fig.width=7, fig.height=3}

# Generate a summary data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, stratum) %>% filter(Vignette == "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(tidy(lm_lin(agree ~ judgment, covariates = ~ stratum, data=.))) %>% #lin estimator is equivalent to stratification w/ discrete covariate
            ungroup() 

# Order the levels of the outcome
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

#Plot it
 p <- ggplot(filter(dfcoef,term=="judgmentdisagree"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~Vignette, ncol=1)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabelsprimary)) + ggtitle("Effect of EC disagreeing with domestic court")

# Print it
print(p)

# Save it
ggsave("Figures/Appendix/Figure C1 - Pride Parade disagreement treatment.png", width = 7, height = 3)

```

Figure C2 - Results of the Pride parade vignette, case outcome treatment (omitted from main text due to implementation problems)

```{r figure c2, echo = F, fig.width=7, fig.height=3}

# Generate the effect data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, stratum) %>% filter(VignetteOutcome == "Pride parade not banned") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(tidy(lm_lin(agree ~ caseOutcome , covariates = ~stratum, data=.)))  %>%
            ungroup() 

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "caseOutcome"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~VignetteOutcome, ncol=1)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabels[1:3])) + ggtitle("Effect of case outcome")

# Print it
print(p)

# Save it
ggsave("Figures/Appendix/Figure C2 - Pride Parade outcome treatment.png", width = 7, height = 3)


```


## Appendix D: Additional analyses

### Estimates without post-stratification

Figures D1/D2 - Main estimates without post-stratification.

```{r figure d1, echo = F}

# Generate a summary data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(tidy(lm_robust(agree ~ judgment, data=.))) %>% #lin estimator is equivalent to stratification w/ discrete covariate
            ungroup() 

# Order the levels of the outcome
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

#Plot it
 p <- ggplot(filter(dfcoef,term=="judgmentdisagree"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~Vignette, ncol=1)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabelsprimary)) + ggtitle("Effect of EC disagreeing with domestic court")

# Print it
print(p)

# Save it
ggsave("Figures/Appendix/Figure D1 - EC Disagreement - no post-stratification.png", width =6, height = 4)

```

```{r figure d2, echo = F}

# Generate the effect data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, stratum) %>% filter(VignetteOutcome != "Pride parade not banned") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(tidy(lm_robust(agree ~ caseOutcome, data=.)))  %>%
            ungroup() 

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "caseOutcome"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~VignetteOutcome, ncol=1)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabels[1:3])) + ggtitle("Effect of case outcome")

# Print it
print(p)

# Save it
ggsave("Figures/Appendix/Figure D2 - Case outcome - no post-stratification.png", width =6, height = 4)

```

### Continuous outcome variables

Figure D3 - effect of european court disagreeing w/ 6-point continuous outcome variable

```{r figure d3, echo = F}

# Generate a summary data frame
dfcoef <- data %>% dplyr::select(D1AgreeC:D3AgreeC, caseOutcome, judgment, Vignette, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1AgreeC:D3AgreeC, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(tidy(lm_lin(agree ~ judgment, covariates = ~ stratum, data=.))) %>% #lin estimator is equivalent to stratification w/ discrete covariate
            ungroup() 

# Order the levels of the outcome
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

#Plot it
 p <- ggplot(filter(dfcoef,term=="judgmentdisagree"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~Vignette, ncol=1)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabelsprimary)) + ggtitle("Effect of EC disagreeing with domestic court\n6-point agree/disagree scale")

# Print it
print(p)


# Save it
ggsave("Figures/Appendix/Figure D3 - EC disagreement - 6-point scale.png", width =6, height = 4)

```

Figure D4 - effect of case outcome w/ 6-point continuous outcome variable

```{r figure d4, echo = F}

# Generate the effect data frame
dfcoef <- data %>% dplyr::select(D1AgreeC:D3AgreeC, caseOutcome, judgment, VignetteOutcome, stratum) %>% filter(VignetteOutcome != "Pride parade not banned") %>%
         pivot_longer(cols=D1AgreeC:D3AgreeC, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(tidy(lm_lin(agree ~ caseOutcome, covariates = ~ stratum, data=.)))  %>%
            ungroup() 

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "caseOutcome"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~VignetteOutcome, ncol=1)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabels[1:3])) + ggtitle("Effect of case outcome\n6-point agree/disagree scale")

# Print it
print(p)

# Save it
ggsave("Figures/Appendix/Figure D4 - Case outcome - 6-point scale.png", width =6, height = 4)

```

### Placebo treatments

Figure D5 - Estimated effect of EC agreeing vs. EC disagreeing alongside the placebo condition (where EC doesn't act)

```{r figure d5, echo=F, fig.width=8, fig.height=3}

#Grouping data and estimating models 
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, stratum) %>% filter(Vignette == "Deportation") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(tidy(lm_lin(agree ~ judgment , covariates = ~ stratum, data=.))) %>%
            ungroup() 

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

dfcoef$term[dfcoef$term == "judgmentdisagree"] <- "EC disagrees"
dfcoef$term[dfcoef$term == "judgmentnocourt"] <- "No EC"

# Make a plot
 p <- ggplot(filter(dfcoef,term=="EC disagrees"|term=="No EC"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, colour=term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") + labs(colour = "Judgment\n(Baseline: EC agrees)") +
  facet_wrap(~Vignette, ncol=1)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabelsprimary)) + ggtitle("Effect of EC disagreeing with domestic court") +
   scale_color_manual(values=c("#000000", "#808080"))

 # Print it
print(p)

# Save it
ggsave("Figures/Appendix/Figure D5 - EC disagreement - placebo.png", width =8, height = 3)


```

Figure D6 - Estimated effect of case outcome - variation by whether EC involved or not

```{r figure d6, echo=F, fig.width=8, fig.height=4}

#Grouping data and estimating models 
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, sympathy, LGBTRights, stratum) %>% filter(Vignette =="Deportation") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*I(judgment=="nocourt") , data=., stratum=stratum)) %>%   mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="caseOutcome",
                            "EC involved", term))
    

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette,  sympathy, LGBTRights, stratum) %>% filter(Vignette =="Deportation")%>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
  mutate(sympathy2 = sympathy*-1+1) %>%
           do(strat_reg(agree ~ caseOutcome*I(judgment!="nocourt") , data=., stratum=stratum)) %>%   mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="caseOutcome",
                            "No EC", term))
                 
dfcoef <- bind_rows(dfcoef,dfcoefflip)

## Reverse order of plotting
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

 p <- ggplot(filter(dfcoef, term == "EC involved" | term == "No EC"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, colour = term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = 1)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour="Presence of EC") +
  facet_wrap(~VignetteOutcome, ncol=1)    + theme_bw()  + ggtitle("Effect of Outcome, by whether EC is mentioned") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimary) +   geom_vline(xintercept=1.5, lty=3) + geom_vline(xintercept=2.5, lty=3) + ylab("Estimate") +
   scale_color_manual(values=c("#808080", "#000000"))

# Print it
print(p)

# Save it
ggsave("Figures/Appendix/Figure D6 - Outcome effect - placebo.png", width =8, height = 3)


```

### Country-specific estimates

Figure D7 - Effect of EC disagreement by country and vignette

```{r figure d7, echo = F, fig.width=8, fig.height=5}

# Generate a summary data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, countryLabel, Vignette, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette, countryLabel) %>%
           do(tidy(lm_lin(agree ~ judgment, covariates = ~ stratum, data=.))) %>% #lin estimator is equivalent to stratification w/ discrete covariate
            ungroup() 

# Order the levels of the outcome
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

#Plot it
 p <- ggplot(filter(dfcoef,term=="judgmentdisagree"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") + scale_y_continuous(breaks = c(-.1, .0, .1)) +
  facet_wrap(~Vignette + countryLabel, ncol=5)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabelsprimary)) + ggtitle("Effect of EC disagreeing with domestic court")

# Print it
print(p)

# Save it
ggsave("Figures/Appendix/Figure D7 - EC disagreement - by country.png", width =8, height = 5)


```

Figure D8 - effect of case outcome by country

```{r figure d8, echo = F, fig.width=8, fig.height=8}

# Generate the effect data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, countryLabel, judgment, VignetteOutcome, stratum) %>% filter(VignetteOutcome != "Pride parade not banned") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome, countryLabel) %>%
           do(tidy(lm_lin(agree ~ caseOutcome, covariates = ~ stratum, data=.)))  %>%
            ungroup() 

dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Plot it
 p <- ggplot(filter(dfcoef, term == "caseOutcome"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = .5)) + geom_hline(yintercept = 0, lty=4, color="grey") + ylab("Estimate") +
  facet_wrap(~VignetteOutcome + countryLabel, ncol=3)    + theme_bw() + scale_x_discrete("Outcome variable", labels=rev(Outcomelabels[1:3])) + ggtitle("Effect of case outcome")

# Print it
print(p)

# Save it
ggsave("Figures/Appendix/Figure D8 - Case outcome - by country.png", width =8, height = 8)


```

Figure D9 - treatment effects by nationalism by country and vignette

```{r figure d9, fig.width = 8, fig.height = 8}

#Grouping data and estimating models 
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, countryLabel, VignetteOutcome, Vignette, National, stratum) %>%
  filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette, countryLabel) %>%
           do(tidy(lm_robust(agree ~ judgment*National + stratum , .))) %>%
  mutate(term=if_else(term=="judgmentdisagree:National",
                            "EC disagrees", term)
         )
  dfcoef2 <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, National, stratum, countryLabel) %>%
  filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette, countryLabel) %>%
           do(tidy(lm_robust(agree ~  caseOutcome*National + stratum, .))) %>%
  mutate(term=if_else(term=="judgmentdisagree:National",
                            "EC disagrees", term),
         term=if_else(term=="caseOutcome:National",
                            "Applicant wins", term)
         )         
dfcoef<- bind_rows(dfcoef,dfcoef2)
  
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Make Plot
 p <- ggplot(filter(dfcoef, term == "EC disagrees" | term =="Applicant wins"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, color=term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = 1)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour = "Treatment") +  
  facet_wrap(~Vignette + countryLabel, ncol=3)    + theme_bw()  + ggtitle("Difference in treatment effects between\nnationalist and non-nationalist respondents") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimaryshort)  + ylab("Estimate") +
   scale_color_manual(values=c("#808080", "#000000"))

 # Print it
 print(p)
 
 # Save it
ggsave("Figures/Appendix/Figure D9 - Heterogeneity - by nationalism and country.png", width =8, height = 8)


```

### Flexible interaction models

Flexible interaction models with nationalism moderator using the continuous outcome for whether the decision should be implemented.

```{r figure d10, echo=F, message=F, warning = F, results='hide',fig.keep='all', fig.width = 8, fig.height = 12}
# Load the interflex library
library(interflex)

### Deportation

# Make the data frame with attitudes towards implementation
df <- as.data.frame(data) %>% filter(Vignette=="Deportation") %>% filter(judgment != "nocourt") %>% 
  select(D2AgreeC, caseOutcome, Natscale)

# Run interflex
out <- interflex(Y = "D2AgreeC", D = "caseOutcome", X = "Natscale", base = 0, data = df, estimator = 'binning', nbins = 3, theme.bw = TRUE, na.rm = TRUE, Ylabel = "Implementation", Dlabel = "Outcome", Xlabel="Nationalism", main="Deportation", ylim=c(-1,.1), ylab=c("Effect on Implementation"))

# Save figure
q <- out$figure

### Quran burning

df <- as.data.frame(data) %>% filter(Vignette=="Quran burning") %>% filter(judgment != "nocourt") %>% 
  select(D2AgreeC, caseOutcome, Natscale)

out <- interflex(Y = "D2AgreeC", D = "caseOutcome", X = "Natscale", base = 0,  data = df, estimator = 'binning', nbins = 3, theme.bw = TRUE, na.rm = TRUE, Ylabel = "Implementation", Dlabel = "Outcome", Xlabel="Nationalism", main="Quran burning", ylab=c("Effect on Implementation"))

p <- out$figure

### Eviction

df <- as.data.frame(data) %>% filter(Vignette=="Eviction") %>% filter(judgment != "nocourt") %>% 
  select(D2AgreeC, caseOutcome, Natscale)

out <- interflex(Y = "D2AgreeC", D = "caseOutcome", X = "Natscale", base = 0,  data = df, estimator = 'binning', nbins = 3, theme.bw = TRUE, na.rm = TRUE, Ylabel = "Implementation", Dlabel = "Outcome", Xlabel="Nationalism", main="Eviction", ylab=c("Effect on Implementation"))

r <- out$figure

### Combine into single figure
figure <- ggarrange(q, p, r,
                    ncol = 1, nrow = 3, common.legend = TRUE, legend = "bottom")

# Print it
print(figure)

 # Save it
ggsave("Figures/Appendix/Figure D10 - Flexible interaction - nationalism.png", width =8, height = 12)
```

Flexible interaction models with authoritarianism moderator.

```{r figure d11, echo=F, message=F, warning = F, results='hide',fig.keep='all', fig.width = 8, fig.height = 12}
# Load the interflex library

### Deportation

# Make the data frame with attitudes towards implementation
df <- as.data.frame(data) %>% filter(Vignette=="Deportation") %>% filter(judgment != "nocourt") %>% 
  select(D2AgreeC, caseOutcome, Autscale)

# Run interflex
out <- interflex(Y = "D2AgreeC", D = "caseOutcome", X = "Autscale", base = 0, data = df, estimator = 'binning', nbins = 3, theme.bw = TRUE, na.rm = TRUE, Ylabel = "Implementation", Dlabel = "Outcome", Xlabel="Authoritarianism", main="Deportation", ylab=c("Effect on Implementation"))

# Save figure
q <- out$figure

### Quran burning

df <- as.data.frame(data) %>% filter(Vignette=="Quran burning") %>% filter(judgment != "nocourt") %>% 
  select(D2AgreeC, caseOutcome, Autscale)

out <- interflex(Y = "D2AgreeC", D = "caseOutcome", X = "Autscale", base = 0, data = df, estimator = 'binning', nbins = 3, theme.bw = TRUE, na.rm = TRUE, Ylabel = "Implementation", Dlabel = "Outcome", Xlabel="Authoritarianism", main="Quran burning", ylab=c("Effect on Implementation"))

p <- out$figure

### Eviction

df <- as.data.frame(data) %>% filter(Vignette=="Eviction") %>% filter(judgment != "nocourt") %>% 
  select(D2AgreeC, caseOutcome, Autscale)

out <- interflex(Y = "D2AgreeC", D = "caseOutcome", X = "Autscale", base = 0, data = df, estimator = 'binning', nbins = 3, theme.bw = TRUE, na.rm = TRUE, Ylabel = "Implementation", Dlabel = "Outcome", Xlabel="Authoritarianism", main="Eviction", ylab=c("Effect on Implementation"))

r <- out$figure

### Combine into single figure
figure <- ggarrange(q, p, r,
                    ncol = 1, nrow = 3, common.legend = TRUE, legend = "bottom")

# Print it
print(figure)

 # Save it
ggsave("Figures/Appendix/Figure D11 - Flexible interaction - authoritarianism.png", width =8, height = 12)
```

### Authoritarianism and Nationalism by Party Preference (figures)

Means + 95\% CIs for authoritarianism (0-1, binary indicator) and nationalism (0-1, binary indicator) by vote intention at time of survey.

Denmark

```{r figure d12, echo = F}

# Average authoriatarianism/nationalism within levels of QE5
dfsum <- data %>% filter(`QE5-DA` != "Fremad") %>% dplyr::select('aut', National, `QE5-DA`) %>% # Drop fremad - only 4 observations!
  filter(`QE5-DA`!="NA") %>%
         pivot_longer(cols=c("aut","National"), names_to = "Outcome", values_to = "agree") %>%
         group_by( Outcome,`QE5-DA` ) %>% 
        summarize(meanA=mean(agree, na.rm = TRUE), sdA=sd(agree, na.rm = TRUE), numA=n(), seA=sdA/sqrt(numA), na.rm = TRUE)

# Make Plot
p <- ggplot(dfsum, aes(y=`QE5-DA`, x=meanA, colour=Outcome)) + 
    geom_pointrange(aes(xmin=meanA-1.96*seA, xmax=meanA+1.96*seA),
                  size=.3,    width=.2,
                  position=position_dodge(.9)) +
  scale_x_continuous(limits=c(0,1)) +
  xlab("Share authoritarian/nationalist") +
  ylab("Party vote intention") +
  scale_colour_discrete(labels = c("Authoritarianism", "Nationalism")) +
 theme_light() 

# Print it
print(p)

 # Save it
ggsave("Figures/Appendix/Figure D12 - authoritarianism and nationalism by party - Denmark.png", width =6, height = 4)

```

Poland

```{r figure d13, echo = F}

# Average authoriatarianism/nationalism within levels of QE5
dfsum <- data  %>% dplyr::select('aut', National, `QE5-PL`) %>% 
  filter(`QE5-PL`!="NA") %>%
         pivot_longer(cols=c("aut","National"), names_to = "Outcome", values_to = "agree") %>%
         group_by( Outcome,`QE5-PL` ) %>% 
        summarize(meanA=mean(agree, na.rm = TRUE), sdA=sd(agree, na.rm = TRUE), numA=n(), seA=sdA/sqrt(numA), na.rm = TRUE)

# Make Plot
p <- ggplot(dfsum, aes(y=`QE5-PL`, x=meanA, colour=Outcome)) + 
    geom_pointrange(aes(xmin=meanA-1.96*seA, xmax=meanA+1.96*seA),
                  size=.3,    width=.2,
                  position=position_dodge(.9)) +
  scale_x_continuous(limits=c(0,1)) +
  xlab("Share authoritarian/nationalist") +
  ylab("Party vote intention") +
  scale_colour_discrete(labels = c("Authoritarianism", "Nationalism")) +
 theme_light() 

# Print it
print(p)

 # Save it
ggsave("Figures/Appendix/Figure D13 - authoritarianism and nationalism by party - Poland.png", width =6, height = 4)


```

Spain

```{r figure d14, echo = F}

# Average authoriatarianism/nationalism within levels of QE5
dfsum <- data  %>% dplyr::select('aut', National, `QE5-ES`) %>% 
  filter(`QE5-ES`!="NA") %>%
         pivot_longer(cols=c("aut","National"), names_to = "Outcome", values_to = "agree") %>%
         group_by( Outcome,`QE5-ES` ) %>% 
        summarize(meanA=mean(agree, na.rm = TRUE), sdA=sd(agree, na.rm = TRUE), numA=n(), seA=sdA/sqrt(numA), na.rm = TRUE)

# Make Plot
p <- ggplot(dfsum, aes(y=`QE5-ES`, x=meanA, colour=Outcome)) + 
    geom_pointrange(aes(xmin=meanA-1.96*seA, xmax=meanA+1.96*seA),
                  size=.3,    width=.2,
                  position=position_dodge(.9)) +
  scale_x_continuous(limits=c(-0.1,1)) +
  xlab("Share authoritarian/nationalist") +
  ylab("Party vote intention") +
  scale_colour_discrete(labels = c("Authoritarianism", "Nationalism")) +
 theme_light() 

# Print it
print(p)

 # Save it
ggsave("Figures/Appendix/Figure D14 - authoritarianism and nationalism by party - Spain.png", width =6, height = 4)



```

France

```{r figure d15, echo = F}

# Average authoriatarianism/nationalism within levels of QE5
dfsum <- data  %>% dplyr::select('aut', National, `QE5-FR`) %>% 
  filter(`QE5-FR`!="NA") %>%
         pivot_longer(cols=c("aut","National"), names_to = "Outcome", values_to = "agree") %>%
         group_by( Outcome,`QE5-FR` ) %>% 
        summarize(meanA=mean(agree, na.rm = TRUE), sdA=sd(agree, na.rm = TRUE), numA=n(), seA=sdA/sqrt(numA), na.rm = TRUE)

# Make Plot
p <- ggplot(dfsum, aes(y=`QE5-FR`, x=meanA, colour=Outcome)) + 
    geom_pointrange(aes(xmin=meanA-1.96*seA, xmax=meanA+1.96*seA),
                  size=.3,    width=.2,
                  position=position_dodge(.9)) +
  scale_x_continuous(limits=c(0,1)) +
  xlab("Share authoritarian/nationalist") +
  ylab("Party vote intention") +
  scale_colour_discrete(labels = c("Authoritarianism", "Nationalism")) +
 theme_light() 

# Print it
print(p)

 # Save it
ggsave("Figures/Appendix/Figure D15 - authoritarianism and nationalism by party - France.png", width =6, height = 4)



```

United Kingdom

```{r figure d16, echo = F}

# Average authoriatarianism/nationalism within levels of QE5
dfsum <- data  %>% dplyr::select('aut', National, `QE5-UK`) %>% 
  filter(`QE5-UK`!="NA") %>%
         pivot_longer(cols=c("aut","National"), names_to = "Outcome", values_to = "agree") %>%
         group_by( Outcome,`QE5-UK` ) %>% 
        summarize(meanA=mean(agree, na.rm = TRUE), sdA=sd(agree, na.rm = TRUE), numA=n(), seA=sdA/sqrt(numA), na.rm = TRUE)

# Make Plot
p <- ggplot(dfsum, aes(y=`QE5-UK`, x=meanA, colour=Outcome)) + 
    geom_pointrange(aes(xmin=meanA-1.96*seA, xmax=meanA+1.96*seA),
                  size=.3,    width=.2,
                  position=position_dodge(.9)) +
  scale_x_continuous(limits=c(0,1)) +
  xlab("Share authoritarian/nationalist") +
  ylab("Party vote intention") +
  scale_colour_discrete(labels = c("Authoritarianism", "Nationalism")) +
 theme_light() 

# Print it
print(p)

 # Save it
ggsave("Figures/Appendix/Figure D16 - authoritarianism and nationalism by party - UK.png", width =6, height = 4)


```

### Interactions with voting intent for right-wing populist parties/euroskepticism

Differences in treatment effects between right-wing populists and non-right-wing populists. Parties included in "right-wing populist" definition: Dansk Folkeparti, Nye Borgerlige, Rassemblement National, Konfeder, Prawo, Vox, Brexit Party, UKIP, BNP. Definitions from Populist: https://popu-list.org/

```{r figure d17, echo = F, fig.width = 8, fig.height = 8}

# Classify parties as populist
data <- data %>% mutate(Populist = case_when(`QE5-DA` == "Dansk Folkeparti" ~ 1,
                                                                    `QE5-DA` == "Nye Borgerlige" ~ 1,
                                                                   `QE5-FR` == "Rassemblement National (RN)" ~ 1,
                                                                  grepl("Konfeder",`QE5-PL`) ~ 1,
                                            grepl("Prawo",`QE5-PL`) ~ 1,
                                            `QE5-ES` == "Vox" ~ 1,
                                            grepl ("Brexit", `QE5-UK`) ~ 1,
                                            grepl ("UKIP", `QE5-UK`) ~ 1,
                                            grepl ("BNP",`QE5-UK`) ~ 1),
                        Populist = ifelse(is.na(Populist), 0, Populist))
                  
# Estimate models for the populist interaction
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette,  stratum, Populist) %>%
  filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(tidy(lm_robust(agree ~ judgment*Populist + stratum , .))) %>%
  mutate(term=if_else(term=="judgmentdisagree:Populist",
                            "EC overturns", term)
         )
  dfcoef2 <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, Populist, stratum) %>%
  filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(tidy(lm_robust(agree ~  caseOutcome*Populist + stratum, .))) %>%
         mutate( term=if_else(term=="caseOutcome:Populist",
                            "Applicant wins", term))
              
dfcoef<- bind_rows(dfcoef,dfcoef2)
  
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Make a plot
 p <- ggplot(filter(dfcoef, term == "EC overturns" | term =="Applicant wins"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, color=term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = 1)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour = "Treatment") +  
  facet_wrap(~Vignette, ncol=1)    + theme_bw()  + ggtitle("Difference in treatment effects between\nRight-wing populist and non-right-wing populist voters") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimary)  + ylab("Estimate") +
   scale_color_manual(values=c("#808080", "#000000"))

 
 # Print it
 print(p)
 
  # Save it
ggsave("Figures/Appendix/Figure D17 - heterogeneity - by rightwing populism.png", width =8, height = 8)


```

Differences in effects based on whether respondents believed that EU membership was a bad thing or a very bad thing


```{r figure d18, echo = F, fig.width = 8, fig.height = 8}
# Do respondents believe EU membership is bad or very bad
data <- data %>% mutate(EUBad = case_when(`QA2` == "Bad" ~ 1,
                                                                    `QA2` == "Very bad" ~ 1),
                        EUBad = ifelse(is.na(EUBad), 0, EUBad)) # If missing class as 0
                  
# Estimate models for the populist interaction
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette,  stratum, EUBad) %>%
  filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(tidy(lm_robust(agree ~ judgment*EUBad + stratum , .))) %>%
  mutate(term=if_else(term=="judgmentdisagree:EUBad",
                            "EC overturns", term)
         )
  dfcoef2 <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, EUBad, stratum) %>%
  filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(tidy(lm_robust(agree ~  caseOutcome*EUBad + stratum, .))) %>%
         mutate( term=if_else(term=="caseOutcome:EUBad",
                            "Applicant wins", term))
              
dfcoef<- bind_rows(dfcoef,dfcoef2)
  
dfcoef$outvar <- factor(dfcoef$outvar, rev(levels(as.factor(dfcoef$outvar))))

# Make a plot
 p <- ggplot(filter(dfcoef, term == "EC overturns" | term =="Applicant wins"), aes(y=estimate, x=outvar, ymin=conf.low, ymax=conf.high, color=term)) + coord_flip() +
  geom_pointrange(position = position_dodge(width = 1)) + geom_hline(yintercept = 0, lty=4, color="grey") + labs(colour = "Treatment") +  
  facet_wrap(~Vignette, ncol=1)    + theme_bw()  + ggtitle("Difference in treatment effects between\nEuroskeptics and non-Euroskeptics") + scale_x_discrete(name="Outcome measure", 
                   breaks=c("D1Agree", "D2Agree", "D3Agree"),
                   labels=Outcomelabelsprimary)  + ylab("Estimate") +
   scale_color_manual(values=c("#808080", "#000000"))

 
 # Print it
 print(p)           

   # Save it
ggsave("Figures/Appendix/Figure D18 - heterogeneity - by Euroskepticism.png", width =8, height = 8)
 
```
### Correlation Matrices

Correlations between nationalism, authoritarianism (binary classification), nationalism scale, EU skepticism and vote intentions for a right-wing populist party

```{r figure d19, fig.width=8, fig.height=8}

# Generate correlation matrix
corrmat <- cor(dplyr::select(data, National, Natscale, aut, Autscale,  EUBad, Populist), method = "pearson", use = "complete.obs")

# Create correlation plot
library(ggcorrplot)

corr_plot_1 <- ggcorrplot(corrmat, type = "lower",
           lab = TRUE) + scale_x_discrete(labels = c("Nationalism\nScale", "Authoritarianism\n(Binary)", "Authoritarianism\nScale", "Euroskeptic", "Populist")) + scale_y_discrete(labels = rev(c("Euroskeptic", "Authoritarianism\nScale","Authoritarianism\n(Binary)", "Nationalism\nScale", "Nationalist\n(Binary)")))

# Print it
print(corr_plot_1)

   # Save it
ggsave("Figures/Appendix/Figure D19 - Correlation matrix 1.png", width =8, height = 8)
 

```

Correlations between the components of the nationalism scales and components of the authoritarianism scales

```{r figure d20, fig.width=9, fig.height=9}

# Generate correlation matrix
corrmat <- cor(dplyr::select(data, National, Aut1, Aut2, Aut3, Aut4, Autscale, Nat1, Nat2, Nat3, Natscale), method = "pearson", use = "complete.obs")

corr_labels <- c("Nationalist\n(Binary)", "Authoritarianism\n(Component 1)",  "Authoritarianism\n(Component 2)",  "Authoritarianism\n(Component 3)",
                  "Authoritarianism\n(Component 4)",  "Authoritarianism\nScale", "Nationalism\n(Component 1)", "Nationalism\n(Component 2)", "Nationalism\n(Component 3)","Nationalism\nScale")

# Create correlation plot
library(ggcorrplot)

corr_plot_2 <- ggcorrplot(corrmat, type = "lower",
           lab = TRUE) + scale_x_discrete(labels = corr_labels[-1]) + scale_y_discrete(labels = corr_labels[-length(corr_labels)])

# Print it
print(corr_plot_2)

   # Save it
ggsave("Figures/Appendix/Figure D20 - Correlation matrix 2.png", width =9, height = 9)

```

## Appendix E: Tables

Table E1 - EC disagreement treatment effects

```{r table e1, echo = F}

# Generate a summary data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, stratum) %>% filter(Vignette != "Pride Parade") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "Outcome", values_to = "agree") %>%
          group_by(Outcome, Vignette) %>%
           do(tidy(lm_lin(agree ~ judgment , covariates = ~ stratum, data=.))) %>% #lin estimator is equivalent to stratification w/ discrete covariate
            ungroup() 

# Subset relevant estimates
df_table <- dfcoef %>% filter(term == "judgmentdisagree") %>% select(Vignette, Outcome, estimate, std.error, statistic)

# Rename Outcomes
df_table$Outcome <- sub("D1Agree", "1) Agree with decision", df_table$Outcome)  
df_table$Outcome <- sub("D2Agree", "2) Should implement decision", df_table$Outcome)  
df_table$Outcome <- sub("D3Agree", "3) Accept authority of European courts", df_table$Outcome)  

# Ordering
df_table <- df_table %>% arrange(Vignette, Outcome)

# Print it
knitr::kable(df_table, digits = 3)

```
Table E2 - EC disagreement treatment effects by domestic rule of law

```{r table e2, echo=F}

# Satisfaction with the law - interaction
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, SatLaw, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(strat_reg(agree ~ judgment*SatLaw , data=., stratum=stratum)) %>% ungroup()

# Get the interaction
df_table <- dfcoef %>% filter(term == "judgmentdisagree:SatLaw")
df_table <- df_table %>% mutate(term = if_else(term == "judgmentdisagree:SatLaw", "3) Difference in effects", term))


# Get baseline effects
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, SatLaw, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(strat_reg(agree ~ judgment*SatLaw , data=., stratum=stratum)) %>% mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="judgmentdisagree",
                            "1) Not satisfied", term))

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, SatLaw, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  mutate(SatLaw2 = SatLaw*-1+1) %>%
           do(strat_reg(agree ~ judgment*SatLaw2 , data=., stratum=stratum)) %>% mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="judgmentdisagree",
                            "2) Satisfied", term))

dfcoef <- rbind(dfcoef, dfcoefflip)

df_table <- rbind(df_table, filter(dfcoef, term == "1) Not satisfied" | term == "2) Satisfied"))

# Subset relevant estimates
df_table$`Satisfaction with domestic rule of law` <- df_table$term
df_table$Outcome <- df_table$outvar

df_table <- df_table %>% select(Vignette, `Satisfaction with domestic rule of law`, Outcome, estimate, std.error, statistic)

# Rename Outcomes
df_table$Outcome <- sub("D1Agree", "1) Agree with decision", df_table$Outcome)  
df_table$Outcome <- sub("D2Agree", "2) Should implement decision", df_table$Outcome)  
df_table$Outcome <- sub("D3Agree", "3) Accept authority of European courts", df_table$Outcome)  

# Ordering
df_table <- df_table %>% arrange(Vignette, `Satisfaction with domestic rule of law`, Outcome)

# Print it
knitr::kable(df_table, digits = 3)

```

Table E3 - EC disagreement treatment effects by nationalism

```{r table e3, fig.width=8, fig.height=12}

#interaction
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, National, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(strat_reg(agree ~ judgment*National , data=., stratum=stratum)) %>% ungroup()

# Get the interaction
df_table <- dfcoef %>% filter(term == "judgmentdisagree:National")
df_table <- df_table %>% mutate(term = if_else(term == "judgmentdisagree:National", "3) Difference in effects", term))


# Get baseline effects

#Group data and estimate interactions for nationalism
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, VignetteOutcome, National, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  do(strat_reg(agree ~ judgment*National , data=., stratum=stratum))  %>%  mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="judgmentdisagree",
                            "2) Not nationalist", term))
                   
dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, VignetteOutcome, National, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  mutate(National2 = National*-1+1) %>%
  do(strat_reg(agree ~ judgment*National2 , data=., stratum=stratum))  %>%  mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="judgmentdisagree",
                            "1) Nationalist", term))

dfcoef <- rbind(dfcoef, dfcoefflip)

df_table <- rbind(df_table, filter(dfcoef, term == "1) Nationalist" | term == "2) Not nationalist"))

# Subset relevant estimates
df_table$`Nationalism` <- df_table$term
df_table$Outcome <- df_table$outvar

df_table <- df_table %>% select(Vignette, `Nationalism`, Outcome, estimate, std.error, statistic)

# Rename Outcomes
df_table$Outcome <- sub("D1Agree", "1) Agree with decision", df_table$Outcome)  
df_table$Outcome <- sub("D2Agree", "2) Should implement decision", df_table$Outcome)  
df_table$Outcome <- sub("D3Agree", "3) Accept authority of European courts", df_table$Outcome)  

# Ordering
df_table <- df_table %>% arrange(Vignette, `Nationalism`, Outcome)

# Print it
knitr::kable(df_table, digits = 3)

```

Table E4 - EC disagreement treatment effects by authoritarianism

```{r table e4, fig.width=8, fig.height=12}

# Interaction
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, aut, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
           do(strat_reg(agree ~ judgment*aut , data=., stratum=stratum)) %>% ungroup()

# Get the interaction
df_table <- dfcoef %>% filter(term == "judgmentdisagree:aut")
df_table <- df_table %>% mutate(term = if_else(term == "judgmentdisagree:aut", "3) Difference in effects", term))


# Get baseline effects

#Group data and estimate interactions for authoritarianism
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, VignetteOutcome, aut, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  do(strat_reg(agree ~ judgment*aut , data=., stratum=stratum))  %>%  mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="judgmentdisagree",
                            "2) Not authoritarian", term))
                   
dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, Vignette, VignetteOutcome, aut, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>%
    filter(judgment != "nocourt") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, Vignette) %>%
  mutate(aut2 = aut*-1+1) %>%
  do(strat_reg(agree ~ judgment*aut2 , data=., stratum=stratum))  %>%  mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="judgmentdisagree",
                            "1) Authoritarian", term))

dfcoef <- rbind(dfcoef, dfcoefflip)

df_table <- rbind(df_table, filter(dfcoef, term == "1) Authoritarian" | term == "2) Not authoritarian"))

# Subset relevant estimates
df_table$`Authoritarianism` <- df_table$term
df_table$Outcome <- df_table$outvar

df_table <- df_table %>% select(Vignette, `Authoritarianism`, Outcome, estimate, std.error, statistic)

# Rename Outcomes
df_table$Outcome <- sub("D1Agree", "1) Agree with decision", df_table$Outcome)  
df_table$Outcome <- sub("D2Agree", "2) Should implement decision", df_table$Outcome)  
df_table$Outcome <- sub("D3Agree", "3) Accept authority of European courts", df_table$Outcome)  

# Ordering
df_table <- df_table %>% arrange(Vignette, `Authoritarianism`, Outcome)

# Print it
knitr::kable(df_table, digits = 3)

```

Table E5 - Case outcome treatment effects

```{r table e5, echo = F}

# Generate the effect data frame
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, stratum) %>% filter(VignetteOutcome != "Pride parade not banned") %>%
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(tidy(lm_lin(agree ~ caseOutcome , covariates = ~stratum, data=.)))  %>%
            ungroup() 

# Subset relevant estimates
dfcoef$`Vignette Outcome` <- dfcoef$VignetteOutcome
dfcoef$Outcome <- dfcoef$outvar
df_table <- dfcoef %>% filter(term == "caseOutcome") %>% select(`Vignette Outcome`, Outcome, estimate, std.error, statistic)

# Rename Outcomes
df_table$Outcome <- sub("D1Agree", "1) Agree with decision", df_table$Outcome)  
df_table$Outcome <- sub("D2Agree", "2) Should implement decision", df_table$Outcome)  
df_table$Outcome <- sub("D3Agree", "3) Accept authority of European courts", df_table$Outcome)  

# Ordering
df_table <- df_table %>% arrange(`Vignette Outcome`, Outcome)

# Print it
knitr::kable(df_table, digits = 3)

```

Table E6 - Case outcome treatment effects interaction with sympathy

```{r table e6, echo = F}


# Interaction
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, sympathy, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*sympathy , data=., stratum=stratum)) %>% ungroup()

# Get the interaction
df_table <- dfcoef %>% filter(term == "caseOutcome:sympathy")
df_table <- df_table %>% mutate(term = if_else(term == "caseOutcome:sympathy", "3) Difference in effects", term))


# Get baseline effects

dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, sympathy, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*sympathy , data=., stratum=stratum)) %>%   mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="caseOutcome",
                            "1) More sympathetic", term))  %>% ungroup()
                   

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette,  sympathy, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
  mutate(sympathy2 = sympathy*-1+1) %>%
           do(strat_reg(agree ~ caseOutcome*sympathy2 , data=., stratum=stratum)) %>%   mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="caseOutcome",
                            "2) Unsympathetic", term))  %>% ungroup()

dfcoef <- rbind(dfcoef, dfcoefflip)

df_table <- rbind(df_table, filter(dfcoef, term == "1) More sympathetic" | term == "2) Unsympathetic"))

# Subset relevant estimates
df_table$`Sympathy with applicant` <- df_table$term
df_table$`Vignette Outcome` <- df_table$VignetteOutcome
df_table$Outcome <- df_table$outvar

df_table <- df_table  %>% select(`Vignette Outcome`, `Sympathy with applicant`, Outcome, estimate, std.error, statistic)

# Rename Outcomes
df_table$Outcome <- sub("D1Agree", "1) Agree with decision", df_table$Outcome)  
df_table$Outcome <- sub("D2Agree", "2) Should implement decision", df_table$Outcome)  
df_table$Outcome <- sub("D3Agree", "3) Accept authority of European courts", df_table$Outcome)  

# Ordering
df_table <- df_table %>% arrange(`Vignette Outcome`, `Sympathy with applicant`, Outcome)

# Print it
knitr::kable(df_table, digits = 3)

```

Table E7 - Case outcome treatment effects interaction with nationalism

```{r table e7, echo = F}

# Interaction
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, National, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*National , data=., stratum=stratum)) %>% ungroup()

# Get the interaction
df_table <- dfcoef %>% filter(term == "caseOutcome:National")
df_table <- df_table %>% mutate(term = if_else(term == "caseOutcome:National", "3) Difference in effects", term))


# Get baseline effects

dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, National, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*National , data=., stratum=stratum)) %>%   mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="caseOutcome",
                            "2) Not nationalist", term))  %>% ungroup()
                   

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette,  National, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
  mutate(National2 = National*-1+1) %>%
           do(strat_reg(agree ~ caseOutcome*National2 , data=., stratum=stratum)) %>%   mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="caseOutcome",
                            "1) Nationalist", term))  %>% ungroup()

dfcoef <- rbind(dfcoef, dfcoefflip)

df_table <- rbind(df_table, filter(dfcoef, term == "1) Nationalist" | term == "2) Not nationalist"))

# Subset relevant estimates
df_table$`Nationalism` <- df_table$term
df_table$`Vignette Outcome` <- df_table$VignetteOutcome
df_table$Outcome <- df_table$outvar

df_table <- df_table  %>% select(`Vignette Outcome`, `Nationalism`, Outcome, estimate, std.error, statistic)

# Rename Outcomes
df_table$Outcome <- sub("D1Agree", "1) Agree with decision", df_table$Outcome)  
df_table$Outcome <- sub("D2Agree", "2) Should implement decision", df_table$Outcome)  
df_table$Outcome <- sub("D3Agree", "3) Accept authority of European courts", df_table$Outcome)  

# Ordering
df_table <- df_table %>% arrange(`Vignette Outcome`, `Nationalism`, Outcome)

# Print it
knitr::kable(df_table, digits = 3)

```

Table E7 - Case outcome treatment effects interaction with nationalism

```{r table e8, echo = F}

# Interaction
dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, aut, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*aut , data=., stratum=stratum)) %>% ungroup()

# Get the interaction
df_table <- dfcoef %>% filter(term == "caseOutcome:aut")
df_table <- df_table %>% mutate(term = if_else(term == "caseOutcome:aut", "3) Difference in effects", term))


# Get baseline effects

dfcoef <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, aut, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
           do(strat_reg(agree ~ caseOutcome*aut , data=., stratum=stratum)) %>%   mutate(term = as.character(term)) %>%
  mutate(term=if_else(term=="caseOutcome",
                            "2) Not authoritarian", term))  %>% ungroup()
                   

dfcoefflip <- data %>% dplyr::select(D1Agree:D3Agree, caseOutcome, judgment, VignetteOutcome, Vignette, aut, LGBTRights, stratum) %>% filter(Vignette != "Pride Parade") %>% 
         pivot_longer(cols=D1Agree:D3Agree, names_to = "outvar", values_to = "agree") %>%
          group_by(outvar, VignetteOutcome) %>%
  mutate(aut2 = aut*-1+1) %>%
           do(strat_reg(agree ~ caseOutcome*aut2 , data=., stratum=stratum)) %>%   mutate(term = as.character(term)) %>%
          mutate(term=if_else(term=="caseOutcome",
                            "1) Authoritarian", term))  %>% ungroup()

dfcoef <- rbind(dfcoef, dfcoefflip)

df_table <- rbind(df_table, filter(dfcoef, term == "1) Authoritarian" | term == "2) Not authoritarian"))

# Subset relevant estimates
df_table$`Authoritarianism` <- df_table$term
df_table$`Vignette Outcome` <- df_table$VignetteOutcome
df_table$Outcome <- df_table$outvar

df_table <- df_table  %>% select(`Vignette Outcome`, `Authoritarianism`, Outcome, estimate, std.error, statistic)

# Rename Outcomes
df_table$Outcome <- sub("D1Agree", "1) Agree with decision", df_table$Outcome)  
df_table$Outcome <- sub("D2Agree", "2) Should implement decision", df_table$Outcome)  
df_table$Outcome <- sub("D3Agree", "3) Accept authority of European courts", df_table$Outcome)  

# Ordering
df_table <- df_table %>% arrange(`Vignette Outcome`, `Authoritarianism`, Outcome)

# Print it
knitr::kable(df_table, digits = 3)

```